<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/app.css" />
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../css/iconfont.css">
    <link href="../script/swiper/swiper.min.css" rel="stylesheet" />
    <style type="text/css">
    html,body{
        height: auto;
    }
    
    	
    .swiper-pagination { bottom: -5px !important; }

    </style>
</head>
<body class="">
	
	
	<div class="H-padding-vertical-bottom-10"></div>
    <div class="H-channel-title H-flexbox-horizontal H-theme-background-color-white H-vertical-middle H-border-vertical-bottom-after">
        <div class="H-channel-line H-theme-background-color-444 H-padding-vertical-top-15 H-padding-horizontal-left-3  H-margin-horizontal-left-10"></div>
        <div class="H-channel-text H-theme-font-color-444 H-flex-item H-font-size-14  H-padding-10 H-margin-horizontal-right-10 H-text-show-row-1">请选择平台</div>
    </div>
    
    
	<div class="H-padding-10 H-theme-background-color-white">
		<input type="radio" name="form" value="3" checked="checked" class="H-radio H-radio-fill H-vertical-align-middle H-font-size-18 H-theme-font-color1 H-border-radius-circle">
		QQ
		
		<input type="radio" name="form" value="2"  class="H-radio H-radio-fill H-vertical-align-middle H-font-size-18 H-theme-font-color1 H-border-radius-circle">
		百度
		
		<input type="radio" name="form" value="1" class="H-radio H-radio-fill H-vertical-align-middle H-font-size-18 H-theme-font-color1 H-border-radius-circle">
		酷狗
		
		<input type="radio" name="form" value="4" class="H-radio H-radio-fill H-vertical-align-middle H-font-size-18 H-theme-font-color1 H-border-radius-circle">
		网易
	</div>
	
	
	<div class="H-padding-10 H-theme-background-color-white">
        <div class="H-search H-flexbox-horizontal H-box-sizing-border-box  H-theme-background-color-f4f4f4 H-border-radius-3 H-overflow-hidden">
            <span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-18 H-theme-font-color-ccc"></i></span>
            <input type="search" name="keyword" id="keyword" placeholder="请输入关键字" class="H-border-none H-theme-background-color-transparent H-flex-item H-font-size-14 H-padding-horizontal-both-10 H-padding-vertical-both-5 H-vertical-align-middle">
            <button onclick="so_keyword();" class="H-button H-font-size-15 H-outline-none H-padding-vertical-both-5 H-padding-horizontal-both-20 H-theme-background-color-497bf0 H-theme-font-color-white H-theme-border-color497bf0 " style="min-width:0;">搜索</button>
        </div>
    </div>
    
   
  
    <div class="H-padding-vertical-bottom-10"></div>
   
    <div id="list"></div>
     <script  id="listtmp" type="text/x-dot-template">
     
     	{{? it && it.length > 0 && form == 4 }}<!--it 就是传入的数组data 这里判断是否为真，数组元素是否大于0个 ?相当于if-->
			{{~ it :v}}<!--it 相当如js的foreach v就是data数组中的一个元素-->
		    <div  class="H-text-list H-flexbox-horizontal  H-theme-background-color-white H-border-vertical-bottom-after H-vertical-middle H-touch-active">
		    	<span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-14 H-theme-font-color-ccc"></i></span>
		        <div class="H-flex-item H-padding-horizontal-both-5 H-font-size-14 H-padding-vertical-both-12  H-theme-font-color497bf0">
		        	{{= v.name}}
		        	<font class="H-theme-font-color-999 H-font-size-14">{{= v.artist[0]}}</font>
		        </div>
		        
		        <span onclick="player_music( '{{=v.id}}' , 4)"  class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-20 H-vertical-middle"><i class="H-iconfont icon-zanting H-font-size-22 H-theme-font-color-ccc"></i></span>
		        
		        <span onclick="music_down( '{{=v.id}}' , 4)" class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-10 H-vertical-middle"><i class="H-iconfont icon-xiangxia5 H-font-size-24 H-theme-font-color-ccc"></i></span>
		        
		        
		        
		    </div>
			{{~}}
		{{?}}<!--相当于/if -->
		
	    {{? it && it.length > 0 && form == 3 }}<!--it 就是传入的数组data 这里判断是否为真，数组元素是否大于0个 ?相当于if-->
			{{~ it :v}}<!--it 相当如js的foreach v就是data数组中的一个元素-->
		    <div  class="H-text-list H-flexbox-horizontal  H-theme-background-color-white H-border-vertical-bottom-after H-vertical-middle H-touch-active">
		    	<span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-14 H-theme-font-color-ccc"></i></span>
		        <div class="H-flex-item H-padding-horizontal-both-5 H-font-size-14 H-padding-vertical-both-12  H-theme-font-color497bf0">
		        	{{= v.songname}}
		        	<font class="H-theme-font-color-999 H-font-size-14">{{= v.singer[0]['name']}}</font>
		        </div>
		        
		        <span onclick="player_music( '{{=v.songmid}}' , 3)"  class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-20 H-vertical-middle"><i class="H-iconfont icon-zanting H-font-size-22 H-theme-font-color-ccc"></i></span>
		        
		        <span onclick="music_down( '{{=v.songmid}}' , 3)" class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-10 H-vertical-middle"><i class="H-iconfont icon-xiangxia5 H-font-size-24 H-theme-font-color-ccc"></i></span>
		        
		        
		        
		    </div>
			{{~}}
		{{?}}<!--相当于/if -->
		
		{{? it && it.length > 0 && form == 2 }}<!--it 就是传入的数组data 这里判断是否为真，数组元素是否大于0个 ?相当于if-->
			{{~ it :v}}<!--it 相当如js的foreach v就是data数组中的一个元素-->
		    <div onclick="" class="H-text-list H-flexbox-horizontal  H-theme-background-color-white H-border-vertical-bottom-after H-vertical-middle H-touch-active">
		    	<span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-14 H-theme-font-color-ccc"></i></span>
		        <div class="H-flex-item H-padding-horizontal-both-5 H-font-size-14 H-padding-vertical-both-12  H-theme-font-color497bf0">
		        	{{= v.title}}
		        	<font class="H-theme-font-color-999 H-font-size-14">{{= v.author}}</font>
		        </div>
		        
		        <span onclick="player_music( '{{=v.song_id}}' , 2)"  class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-20 H-vertical-middle"><i class="H-iconfont icon-zanting H-font-size-22 H-theme-font-color-ccc"></i></span>
		        
		        <span onclick="music_down( '{{=v.song_id}}' , 2)" class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-10 H-vertical-middle"><i class="H-iconfont icon-xiangxia5 H-font-size-24 H-theme-font-color-ccc"></i></span>
		    </div>
			{{~}}
		{{?}}<!--相当于/if -->
		
		{{? it && it.length > 0 && form == 1 }}<!--it 就是传入的数组data 这里判断是否为真，数组元素是否大于0个 ?相当于if-->
			{{~ it :v}}<!--it 相当如js的foreach v就是data数组中的一个元素-->
		    <div onclick="" class="H-text-list H-flexbox-horizontal  H-theme-background-color-white H-border-vertical-bottom-after H-vertical-middle H-touch-active">
		    	<span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-14 H-theme-font-color-ccc"></i></span>
		        <div class="H-flex-item H-padding-horizontal-both-5 H-font-size-14 H-padding-vertical-both-12  H-theme-font-color497bf0">
		        	{{= v.songname}}
		        	<font class="H-theme-font-color-999 H-font-size-14">{{= v.singername}}</font>
		        </div>
		        
		        <span onclick="player_music( '{{=v.hash}}' , 1)" class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-20 H-vertical-middle"><i class="H-iconfont icon-zanting H-font-size-22 H-theme-font-color-ccc"></i></span>
		        
		        <span  onclick="music_down( '{{=v.hash}}' , 1)" class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-right-10 H-vertical-middle"><i class="H-iconfont icon-xiangxia5 H-font-size-24 H-theme-font-color-ccc"></i></span>
		    </div>
			{{~}}
		{{?}}<!--相当于/if -->
    </script>
    <!--<div class="H-text-list H-flexbox-horizontal  H-theme-background-color-white H-border-vertical-bottom-after H-vertical-middle H-touch-active">
    	<span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-14 H-theme-font-color-ccc"></i></span>
        <div class="H-flex-item H-padding-horizontal-both-5 H-font-size-14 H-padding-vertical-both-12">列表名称</div>
    </div>
    <div class="H-text-list H-flexbox-horizontal  H-theme-background-color-white H-border-vertical-bottom-after H-vertical-middle H-touch-active">
    	<span class="H-icon H-display-block H-padding-horizontal-right-0 H-margin-horizontal-left-10 H-vertical-middle"><i class="H-iconfont H-icon-search H-font-size-14 H-theme-font-color-ccc"></i></span>
        <div class="H-flex-item H-padding-horizontal-both-5 H-font-size-14 H-padding-vertical-both-12">列表名称</div>
    </div>-->


	
  
	
	<audio src="b.mp3" controls="controls" controlsList="nodownload" preload id="music" style="display:none;position: fixed;bottom: 0;width:100%;" >
</audio>
    
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="../script/app.js"></script>
<script type="text/javascript" src="../script/doT.js"></script>
<script type="text/javascript">


    
	var sysconfig = "";//获取系统配置参数 , 参数内容在后台接口获取
	
	
	var form = "1";
	var page    = 1;
	var q    = "";
	
    apiready = function(){
    	sysconfig = $api.getStorage('sysconfig');
    	
    	so_list = $api.getStorage('so_list');
    	if(typeof so_list =='undefined' || so_list ==null || so_list =='' ){
    		so_list = [];
    	}
    	
		api.parseTapmode();
		
		get_so_list();
		
    };
    
    function get_so_list(){
    	$("#list").html("");
    	var evalText = doT.template($("#so_list").text());
		$("#list").html(evalText(so_list));
					
    }
    
    
    function so_keyword(){
    	api.showProgress({
		    title: '努力加载中...',
		    text: '先喝杯茶...',
		    modal: false
		});
    	page = 1;
    	form = $("input[name='form']:checked").val();
    	keyword  = $("#keyword").val();
    	$app.ajax($app.serverUrl+"index/music/so",{
    		'q':keyword ,
    		'p':page ,
    		'form': form
    	},'get',function(ret){
    		api.hideProgress();

			if( ret.code == 1000){
				var evalText = doT.template($("#listtmp").text());
				if( page ==1 ){
					$("#list").html(evalText(ret.result));
				} else {
					$("#list").append(evalText(ret.result));
				}
			} else {
				$app.toast( ret.msg);
			}
		});
    }
    
    
    function player_music( id , type ){
    	if(type == 1 ){
    		down_url=$app.serverUrl+"index/music/download?hash=" + id;
    	}
    	if(type == 2 ){
    		down_url = $app.serverUrl+"index/music/download?wyy_id=" + id + "&source=baidu";
    	}
    	if(type == 3 ){
    		down_url=$app.serverUrl+"index/music/download?songmid=" + id;
    	}
    	
    	if(type == 4 ){
    		down_url = $app.serverUrl+"index/music/download?wyy_id=" + id;
    	}
    	
    	
    	$("#music").attr('src' , down_url);
    	$("#music").css('display' , 'block');
    	var audio = document.getElementById('music'); 
		audio.play();// 播放 

    }
    
    
    function music_down( id , type ){
    
    	token = localStorage.getItem('token');
		if(token !='' && token!=null  && typeof token !='undefined'){
		
			userInfo = $api.getStorage('userinfo');
				if( userInfo.vip == 1  || userInfo.vip == 2){
					$(".is_vip").show();
					$(".is_vip span").text('体验会员');
					$("#vip_desc").text( "当前为体验会员" );
					
				} else {
					$app.toast( '普通用户不支持下载' );
					return ;
				}
		} else {
			$app.toast( '请先登录' );
			return false;
		}
			
    	if(type == 1 ){
    		down_url=$app.serverUrl+"index/music/download?hash=" + id;
    	}
    	if(type == 2 ){
    		down_url = $app.serverUrl+"index/music/download?wyy_id=" + id + "&source=baidu";
    	}
    	if(type == 3 ){
    		down_url=$app.serverUrl+"index/music/download?songmid=" + id;
    	}
    	
    	if(type == 4 ){
    		down_url=$app.serverUrl+"index/music/download?wyy_id=" + id;
    	}
    	
      	console.log('down_url:' + down_url);
    	var clipBoard = api.require('clipBoard');
		clipBoard.set({
		    value: down_url
		}, function(ret, err) {
		    if (ret) {
		        $app.toast( '已复制到剪切板，请使用浏览器下载');
		        api.openApp({
				    androidPkg: 'android.intent.action.VIEW',
				    mimeType: 'text/html',
				    uri: down_url
				},function(ret,err){
				    var msg = JSON.stringify(ret);
				});
		    } else {
		        alert(JSON.stringify(err));
		    }
		});

    	

//  	api.download({
//	        url:down_url
//      },function(ret,err){
//      	
//      	api.alert({msg:ret});
//      });
    }
    

    

	
</script>
</html>